<template>
  <div class="page">
    <div class="head">
      <h1>{{ $t('系统消息') }}</h1>
    </div>
    <div class="panel" v-for="(item,index) in records" :key="index">
      <h2>{{ item.createTime | formatTime }}</h2>
      <p>{{ item.msg }}</p>
    </div>
    <infinite-loading @infinite="initData" ref="infiniteLoading2">
      <span slot="no-more"></span>
      <div slot="no-results">
        <br>
        <empty></empty>
      </div>
      <spinner slot="spinner" type="lines"></spinner>
    </infinite-loading>
  </div>
</template>

<script>
  import {
    Spinner,
  } from 'vux'
  import empty from './common/empty.vue'
  import InfiniteLoading from 'vue-infinite-loading';
  export default {
    components: {
      empty,
      InfiniteLoading,
      Spinner
    },
    data() {
      return {
        records: [],
        current: 1
      }
    },
    methods: {
      initData($state) {
        this.$http
          .post(`/users/sysMessage`, {
            current: this.current
          })
          .then(res => {
            if (res.code == 200) {
              if (res.result.total > 0) {
                this.records = this.records.concat(res.result.records);
                $state.loaded();
                if (res.result.current < res.result.pages) {
                  this.current += 1;
                } else {
                  $state.complete();
                }
              } else {
                $state.complete();
              }
            } else {}
          })
          .catch(function(error) {});
      }
    }
  }
</script>

<style lang="scss" scoped>
  .panel {
    h2 {
      font-size: 16px;
    }
    p {
      font-size: 14px;
      line-height: 1.4;
      text-align: justify;
      color: $gray;
    }
  }
</style>